<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="店铺名称：">
          <el-input v-model="formInline.shopName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="团购名称：">
          <el-input v-model="formInline.grouponName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="用户手机号：">
          <el-input v-model="formInline.customerPhone" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="订单来源：">
          <el-select v-model="formInline.paySource" placeholder="请选择">
            <el-option v-for="item in paySourceList" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态：">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option v-for="item in options3" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交易时间：">
          <el-date-picker :clearable="false" v-model="date" type="daterange" value-format="yyyy-MM-dd"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button class="sumit_button" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <export-excel-button title="团购订单" action="/groupon/order/v1/export" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:operate="{ scope }">
          <el-button @click="lookDetail(scope.row.id)" size="small">查看</el-button>
        </template>
      </ex-table>
    </div>
    <!-- 交易快照 -->
    <el-dialog title="交易快照" v-loading="dialogLoading" :visible.sync="centerDialogVisible" :close-on-click-modal="true" width="500px" center>
      <div class="dialog_one">
        <div class="dialog_box">
          <span class="el-icon-tickets icont_font"></span>
          <span>套餐详情</span>
        </div>
        <div class="dialog_one_title">{{info.grouponName}}</div>
        <div class="dialog_one_ls" v-for="(item,index) in info.productDetail" :key="index">
          <span>{{index+1}}、{{item.productName}}</span>
          <span>({{item.productNum}})</span>
        </div>
      </div>
      <div class="dialog_one">
        <div class="dialog_box">
          <span class="el-icon-shopping-cart-full icont_font"></span>
          <span>购买须知</span>
        </div>
        <div class="dialog_one_title">使用时间</div>
        <div class="dialog_one_ls">{{info.useStartTime}} 至 {{info.useStartTime}}</div>
        <div class="dialog_one_title">营业时间</div>
        <div class="dialog_one_ls">{{info.weekTime}} {{info.startTime}}-{{info.endTime}}</div>
        <div class="dialog_one_title">使用方式</div>
        <div class="dialog_one_ls">到店核销</div>
        <div class="dialog_one_title" v-if="info.useRule!=''">使用规则</div>
        <div class="dialog_one_ls" style="line-height: 25px" v-if="info.useRule!=''">
          {{info.useRule}}
        </div>
      </div>
      <div class="dialog_one">
        <div class="dialog_box">
          <span class="el-icon-notebook-2 icont_font"></span>
          <span>图文详情</span>
        </div>
        <div class="carousel_box_two" v-if="info.detailList.length != 0">
          <div class="phone_box" v-for="(item, indexs) in info.detailList" :key="indexs">
            <el-image class="swiper_img" :src="item" fit="cover"></el-image>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  // components
  import {
    adminDict,
    grouponOrdetLs,
    snapshoot
  } from "@/api/operateActive";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import {
    mapGetters
  } from "vuex";
  export default {
    name: "billList",
    components: {
      ExportExcelButton,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        centerDialogVisible: false,
        commodityImg: [
          "group1/M00/00/28/rBAAD2JY3FKAevy5AAAS7UD31wQ564.png",
          "group1/M00/00/28/rBAAD2JZHVeAaJbxAAAT0K_0Q38113.png",
        ],
        formInline: {
          customerPhone: "", //手机号
          grouponName: "", //团购名称
          shopName: "", //店铺名称
          status: "", //订单状态
          paySource: '',//订单来源
          transactionStartTime: "", //交易起始时间
          transactionEndTime: "", //交易结束时间
        },
        date: [],
        detailInfo: {},
        tableData: [],
        options3: [],
        paySourceList: [
          {id: 1, value: '微信小程序'},
          {id: 2,value: '抖音小程序'}
        ],
        fromTotalType: "PrepaidCardflow",
        tableColumn: [{
            prop: "orderNo",
            label: "交易单号"
          },
          {
            prop: "paySourceDict",
            label: "订单来源",
            width: 100
          },
          {
            prop: "shopName",
            label: "店铺名称"
          },
          {
            prop: "grouponName",
            label: "团购名称"
          },
          {
            prop: "customerName",
            label: "会员名称",
            width: 155
          },
          {
            prop: "customerPhone",
            label: "手机号"
          },
          {
            prop: "transactionTime",
            label: "交易成功时间"
          },
          {
            prop: "statusDict",
            label: "订单状态",
            width: 120
          },
          {
            prop: "payMoney",
            label: "交易金额"
          },
          {
            prop: "returnMoney",
            label: "退款金额"
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate",
            width: 120,
            fixed: "right",
          },
        ],
        info: {
          detailList:'',
        },//交易快照
        dialogLoading: false,
      };
    },
    computed: {
      ...mapGetters(["isChain"]),
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        return params;
      },
    },
    created() {},
    mounted() {
      this.getOrdertype();
      this.getList();
    },
    methods: {
      getOrdertype() {
        //获取订单状态
        const params = {
          dictType: "customer_groupon_order_status",
        };
        adminDict(params).then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.options3 = arr.concat(res.result[0].dictList);
        });
      },
      search() {
        //搜索
        console.log(this.formInline);
        this.formInline.transactionStartTime = this.date[0];
        this.formInline.transactionEndTime = this.date[1];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        // this.formInline.fundFlow = ''
        // this.formInline.billType = ''
        this.date = [];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {

        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        grouponOrdetLs(params)
          .then((res) => {
            this.tableData = res.result.records;
            this.tableData.forEach((item) => {
              let ls = this.tableData;
              ls.forEach((item) => {
                Object.keys(item).forEach((key) => {
                  if (!item[key]) {
                    item[key] = "-";
                  }
                });
              });
              item.payMoney = '￥' + item.payMoney
              item.returnMoney = '￥' + item.returnMoney
            });
            this.$refs.table.pageOptions.total = res.result.total;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      getSnapshoot(id) { //获取交易快照
        this.dialogLoading = true
        snapshoot(id).then((res) => {
            this.info = res.result
            this.info.productDetail = JSON.parse(this.info.productDetail)
            this.dialogLoading = false;
          })
          .finally(() => {
            this.dialogLoading = false;
          });
      },
      lookDetail(id) {
        this.getSnapshoot(id)
        this.centerDialogVisible = true;
      },
    },
  };

</script>
<style lang="scss" scoped>
  .el-card-title {
    font-size: 20px;
  }

  .head {
    //   box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 20px;
  }

  .listBox {
    //   box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
    background-color: #fff;
    border-radius: 8px;
    //   height: 120px;
    padding: 20px 20px;
    margin-top: 10px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }

  .sumit_button {
    color: #fff !important;
    background: #ff7b35 !important;
    border: 0;
  }

  .dialog_one {
    border-bottom: 1px solid #eaeaea;
    padding-bottom: 8px;
    margin-bottom: 15px;
  }

  .dialog_box {
    display: flex;
    align-items: center;
    font-size: 16px;
    color: #222222;
    font-weight: bold;
  }

  .icont_font {
    font-size: 16px;
    color: #fc550e;
    margin-right: 10px;
  }

  .dialog_one_title {
    font-size: 15px;
    color: #222222;
    margin: 12px 0px 8px 28px;
  }

  .dialog_one_ls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #666666;
    margin-bottom: 10px;
    padding: 0 0 0 28px;
  }

  .swiper_img {
    width: 100%;
    height: 100%;
  }

  .carousel_box_two {
    margin-top: 20px;
  }

  .phone_box {
    width: 100%;
  }

</style>
